package se581.banker.util;

/**
 * Wrapper object for server socket connection info
 * 
 * @author mmichalak
 *
 */
public class ServerSocketInfo {

	String _host = null;
	String _port = null;
	
	
	public ServerSocketInfo() { ; }
	
	/**
	 * 
	 * @param serverPort - server:port String
	 */
	public ServerSocketInfo(String serverPort) {
		String[] tokens = serverPort.split(":");
		_host = tokens[0];
		_port = tokens[1];
	}
	
	public String getHost() {
		return _host;
	}
	public void setHost(String _host) {
		this._host = _host;
	}
	public String getPort() {
		return _port;
	}
	public void setPort(String _port) {
		this._port = _port;
	}
	
	
	public String toSerializeString() {
		return  _host + ":" + _port;
	}
	
	
	@Override
	public String toString() {
		return "ServerSocketInfo [_host=" + _host + ", _port=" + _port + "]";
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((_host == null) ? 0 : _host.hashCode());
		result = prime * result + ((_port == null) ? 0 : _port.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ServerSocketInfo other = (ServerSocketInfo) obj;
		if (_host == null) {
			if (other._host != null)
				return false;
		} else if (!_host.equals(other._host))
			return false;
		if (_port == null) {
			if (other._port != null)
				return false;
		} else if (!_port.equals(other._port))
			return false;
		return true;
	}
	
	
	
}
